/*
 * Virtual Earth Screensaver
 * Keith Kinnan
 * 5/12/2007
 * 9/30/2006
 * 
 * Portions of this code is based on the Visual Studio 2005 Starter Kit RSS Screen Saver:
 * http://msdn.microsoft.com/vstudio/express/visualcsharp/starterkit/default.aspx#rssss
 */

using System;
using System.Windows.Forms;
using System.Globalization;
using System.Security.Permissions;

[assembly: CLSCompliant(true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, Execution = true)]
namespace VirtualEarthScreensaver
{
    static class Program
    {
        /// <summary>
        /// Return Codes
        /// </summary>
        public enum ExitCode
        {
            Exit = 0,
            UpdateFeed = 1,
        }

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                // Get the 2 character command line argument
                string arg = args[0].ToLower(CultureInfo.InvariantCulture).Trim().Substring(0, 2);
                switch (arg)
                {
                    case "/c":
                        // Show the options dialog
                        ShowOptions();
                        break;
                    case "/p":
                        // Don't do anything for preview
                        break;
                    case "/s":
                        // Show screensaver form
                        ShowScreenSaver();
                        break;
                    default:
                        MessageBox.Show(string.Format(CultureInfo.InvariantCulture, Properties.Resources.StrInvalidCommand, arg), Properties.Resources.StrVEScreensaverTitle, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                        break;
                }
            }
            else
            {
                // If no arguments were passed in, show the screensaver
                ShowScreenSaver();
            }
        }

        /// <summary>
        /// Show Options Form
        /// </summary>
        static void ShowOptions()
        {
            OptionsForm optionsForm = new OptionsForm();
            Application.Run(optionsForm);
        }

        /// <summary>
        /// Show Screen Saver
        /// </summary>
        static void ShowScreenSaver()
        {
            ExitCode returnCode = ExitCode.Exit;
            do
            {
                using (ScreenSaverForm screenSaver = new ScreenSaverForm())
                {
                    Application.Run(screenSaver);
                    returnCode = screenSaver.ReturnCode;
                }
            } while (returnCode == ExitCode.UpdateFeed);
        }
    }
}